
package com.core.controller;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public abstract class B5MBaseFragment extends Fragment
{
    protected View containerView;
    public Context mContext;
    public Activity mActivity;
    public Button bt_left, bt_right;
    public TextView tv_title;
    public ProgressBar mProgressBar;

    @Override
    public View onCreateView(LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState)
    {
        if (containerView == null)
        {
            containerView = inflater.inflate(doGetContentViewId(), container, false);
            doBefore(savedInstanceState);
            init();
            doInitSubViews(containerView);
            doInitDataes();
            doAfter();
        }
        ViewGroup parent = (ViewGroup) containerView.getParent();
        if (parent != null)
        {
            parent.removeView(containerView);
        }
        return containerView;
    }

    private void init()
    {
        // TODO Auto-generated method stub
        mActivity = getActivity();
        mContext = getActivity();
        if ((mActivity instanceof B5MBaseActivity) && !((B5MBaseActivity) mActivity).isNoTitle())
        {
            initTitle();
        }
    }

    private void initTitle()
    {
        bt_left = ((B5MBaseActivity) mActivity).bt_left;
        bt_right = ((B5MBaseActivity) mActivity).bt_right;
        tv_title = ((B5MBaseActivity) mActivity).tv_title;
        mProgressBar = ((B5MBaseActivity) mActivity).mProgressBar;
    }

    public abstract int doGetContentViewId();

    public abstract void doInitSubViews(View containerView);

    public abstract void doInitDataes();

    public abstract void doAfter();

    private void doBefore(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
    }
}
